#include <stdio.h>
#include <string.h>
int main(int argc,char *argv[])
{
	if(argc < 2)
	{
		fprintf(stdout,"parameter error\n");
		return 1;
	}
	FILE *fp1 = fopen("/etc/passwd","r");
	FILE *fp2 = fopen(argv[1],"r");
	char str[1024] = {'\0'},name[20] = {'\0'},passwd[20] = {'\0'},description[20] = {'\0'},home[20] = {'\0'},bash[20] = {'\0'};
	int uid = 0,gid = 0;
	// 这里读取之后，整行的内容都在name中
	int flag = fscanf(fp1,"%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%[^\n]\n",name,passwd,&uid,&gid,description,home,bash); 
	while((flag = fscanf(fp1,"%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%[^\n]\n",name,passwd,&uid,&gid,description,home,bash))!= EOF)
	{
		printf("%d\n",flag);
		fprintf(stdout,"name=%s;passwd=%s;uid=%d;gid=%d;description=%s;home=%s;bash=%s\n",name,passwd,uid,gid,description,home,bash);
		// description位置可能会为空，为空的话，文件指针的位置不会移动到下一行，这个需要处理下
		if(0 == flag)
		{
			fscanf(fp1,"%*[^\n]\n");
			// 清空description的数据
			memset(description,'\0',sizeof(description));
			//break;
		}
	}
	return 0;
}
